﻿@{
}
<section class="container-fluid m15_t">
    <div class="data-wrap case">
        <form class="form-inline" id="formSearch" onsubmit="return false;">
            <div class="data-tool clearfix">
                <div class="pull-left form-inline ">
                    <input class="hide" name="file" id="upfile" type="file" />
                    <a class="btn btn-default btn-sm paymentRecordImport m10_l" href="javascript:void(0)" data-title="新增订单">新增订单</a>
                    <div class="input-group input-group-sm">
                        <div class="input-sm"><input name="autoRefresh" type="checkbox" title="10秒自动刷新" /> <label id="time" class="wd125 gettext">10秒自动刷新</label></div>
                    </div>
                </div>
                <div class="pull-right">

                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">通知状态：</label>
                        <select class="form-control gettext" name="noticeStatus">
                            <option value="">请选择</option>
                            <option value="1">未通知</option>
                            <option value="2">通知成功</option>
                            <option value="3">通知失败</option>
                            <option value="4">通知中</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l gettext">支付状态：</label>
                        <select class="form-control gettext" name="PaymentStatus">
                            <option value="">请选择</option>
                            <option value="1">未审核</option>
                            <option value="2">付款成功</option>
                            <option value="3">付款失败</option>
                            <option value="4">付款中</option>
                            <option value="5">取消付款</option>
                        </select>
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">商户订单号：</label>
                        <input class="form-control" name="MerchantOrderNo" type="text" autocomplete="off">
                    </div>

                    <button type="button" class="btn btn-default btn-sm active gettext" id="btnSearch">搜索</button>
                    <button type="button" class="btn btn-default btn-sm gettext" id="AdvSearch">高级搜索</button>

                </div>
            </div>
            <!--一高级搜索开始-->
            <div class="AdvSearch">
                <div class="AdvSearchcom collapse">
                    <table>
                        <tbody>
                            <tr>
                                <td class="gettext">创建时间：</td>
                                <td rowspan="3">
                                    <input id="d421" class="Wdate wd175" name="startTime" type="text" value="@(ViewBag.StartTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" autocomplete="off" />
                                    -
                                    <input id="d422" class="Wdate wd175 m5_l" name="endTime" type="text" value="@(ViewBag.EndTime)" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'d421\')}'})" autocomplete="off" />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="AdvSearchfooter t_c">
                        <button id="search" class="btn btn-default btn-sm gettext" type="button">立即搜索</button>
                        <button id="cancel" data-dismiss="modal" class="btn btn-default btn-sm gettext" type="button">取消</button>
                    </div>
                </div>
            </div>
        </form>


        <div class="data-easyui data-scroll">
            <div class="data-view">
                <div class="data-div-view table-responsive">
                    <table class="table" id="pager"></table>
                </div>
            </div>
        </div>
    </div>
</section>
@section footerScript{
    <script src="~/js/clipboard.min.js"></script>
    <script type="text/javascript">

        var pageSize = 10;
        var autoRefresh = $("input[name='autoRefresh']");

        $(function () {
            FlashPay.UI.DataAutoHeight();

            doSearch();

            $("#btnSearch").click(function () {
                doSearch();
            });

            $(autoRefresh).change(function () {
                wait = 10;
                time();
            });

            FlashPay.UI.Triggerbox({
                btnAdvSearch: '#AdvSearch',
                searchCallBack: function () {
                    window.currentPage = null;
                    doSearch();
                },
                cancelCallBack: function () {

                }
            });

            var clipboard = new Clipboard('.copy');
            clipboard.on('success', function (e) {
                alert("已复制成功")
            });
            clipboard.on('error', function (e) {
                alert("您的浏览器可能不支持，请手动复制.")
            });

            $("a.paymentRecordImport").click(function () {
                $("input[name='file']").click();
            });

            $("input[name='file']").change(function () {

                var val = $("input[name='file']").val();
                if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                    var fileUpload = $("input[name='file']").get(0);
                    var files = fileUpload.files[0];

                    if (files.length > 1) {
                        FlashPay.UI.Tip_short_warning("只能上传单文件.");
                        return false;
                    }

                    var data = new FormData();
                    data.append(files.name, files);

                    var cover = FlashPay.UI.Mask({
                        obj: $("body"),
                        opacity: 0.5
                    });

                    FlashPay.Util.Ajax({
                        url: '/Business/UploadFiles',
                        type: 'POST',
                        contentType: false,
                        processData: false,
                        data: data,
                        success: function (res) {
                            cover.Remove();
                            if (res.success) {
                                FlashPay.UI.DialogOpener().Tip_success("汇入成功。");
                                FlashPay.UI.DialogOpener().doSearch();
                                FlashPay.UI.CloseDialog();
                            } else {
                                FlashPay.UI.Tip_short_warning(res.errorMessage);
                            }
                            $("input[name='file']").val("");
                        },
                        error: function (json) {
                            cover.Remove();
                            FlashPay.UI.Tip_short_warning("操作失败！请查看网络，请重试。");
                            $("input[name='file']").val("");
                        }
                    });
                } else {

                }
                alert(1);
            })
        });

        //倒时计
        function time() {

            var language = FlashPay.Util.Language();

            var obj = document.getElementById("time");

            var isauto = $(autoRefresh).is(':checked');
            if (!isauto) {

                obj.innerText = "10 秒自动刷新";

                return false;
            }

            if (wait == 0) {
                obj.innerText = "10秒自动刷新";

                wait = 10;

                if (isauto) {
                    setTimeout(function () { time(); }, 1000);
                }

                FlashPay.UI.DoSearch();
            } else {
                obj.innerText = wait + "秒自动刷新";
                wait--;
                setTimeout(function () { time(); }, 1000);
            }
        }

        function Tip_success(word) {
            FlashPay.UI.Tip_success(word);
        }

        function getParams() {
            var params = $("#formSearch").serializeJSON();
            return params;
        }

        function doSearch() {
            var frozenColumns = [[
                {
                    field: '_Id', title: "订单号", width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                { field: 'merchantName', title: "商户", width: 75, align: 'left' },
                {
                    field: 'merchantOrderNo',
                    title: "商户订单号",
                    width: 150,
                    align: 'left',
                    formatter: function (val, item) {

                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {

                            var result = '<span class="f_l">{0}</span>'.format(val);;

                            return result;

                        } else {
                            return "";
                        }

                    }
                }
            ]];
            var columns = [[
                //{
                //    field: 'proxyMerchantName',
                //    title: '组',
                //    width: 50,
                //    align: 'center',
                //    formatter: function (val, item) {
                //        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                //            return '<span class="">{0}</span>'.format(val);
                //        } else {
                //            return "";
                //        }
                //    }
                //},
                {
                    field: '_WithdrawalAmount',
                    title: '代付金额',
                    width: 75,
                    align: 'left',
                    //formatter: function (val, item) {
                    //    if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                    //        return '<span class="f_l red bold">{0}</span><span class="f_r"><a class="copy" data-clipboard-text="{0}">复制</a></span>'.format(val);
                    //    } else {
                    //        return "";
                    //    }
                    //}
                },
                {
                    field: '_WithdrawalFee',
                    title: '手续费',
                    width: 75,
                    align: 'right'
                },
                {
                    field: 'withdrawalBankName',
                    title: '银行名称',
                    width: 90,
                    align: 'left'
                },
                {
                    field: 'withdrawalCardName',
                    title: '姓名',
                    width: 75,
                    align: 'left',
                    //formatter: function (val, item) {
                    //    if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                    //        return '<span class="f_l">{0}</span><span class="f_r"><a class="copy" data-clipboard-text="{0}">复制</a></span>'.format(val);
                    //    } else {
                    //        return "";
                    //    }
                    //}
                },
                {
                    field: 'withdrawalCardNumber',
                    title: '卡号',
                    width: 150,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '<span class="f_l">{0}</span>'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: '_PaymentDate',
                    title: '付款时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: 'paymentStatus',
                    title: '支付状态',
                    width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        var result = '';

                        if (val == 1) {
                            result += '<span class="bold">未审核</span>';
                        } else if (val == 2) {
                            result = '<span class="green bold">付款成功</span>';
                        } else if (val == 3) {
                            result = '<span class="red bold">付款失败</span>';
                        } else if (val == 4) {
                            result = '<span class="bold">付款中</span>';

                        } else if (val == 5) {
                            result = '<span class="bold">取消付款</span>';
                        } else if (val == 6) {
                            result = '<span class="bold">撤销</span>';
                        }

                        return result;
                    }
                },
                {
                    field: 'noticeStatus',
                    title: '通知状态',
                    width: 75,
                    align: 'left',
                    formatter: function (val, item) {
                        /**
                         * 1、未通知
                         * 2、通知成功
                         * 3、通知失败
                         * 4、通知中
                         * */
                        var result = "";

                        if (val == 1) {
                            result = '<span class="bold">未通知</span>';
                        } else if (val == 2) {
                            result = '<span class="green bold">通知成功</span>';
                        } else if (val == 3) {
                            result = "<span class='red bold' title='{0}'>通知失败</span>".format(item.noticeFail);
                        } else if (val == 4) {
                            result = '<span class="bold">通知中</span>';
                        }

                        return result;
                    }
                },
                {
                    field: '_NoticeLastTime',
                    title: '最后通知时间',
                    width: 120,
                    align: 'left'
                },
                {
                    field: 'noticeTimes',
                    title: '通知次数',
                    width: 60,
                    align: 'left',
                    formatter: function (val, item) {

                        var result = '{0}'.format(val);

                        return result;
                    }
                },
                {
                    field: '_HandTime',
                    title: '处理时间/操作人',
                    width: 200,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}/{1}'.format(item._HandTime, item._HandBy);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注',
                    width: 100,
                    align: 'left',
                    formatter: function (val, item) {
                        if (!FlashPay.Util.isNullOrEmptySpance(val)) {
                            return '{0}'.format(val);
                        } else {
                            return "";
                        }
                    }
                },
                {
                    field: '_CreatedDate',
                    title: '下单时间',
                    width: 120,
                    align: 'left'
                },
            ]];

            $("#pager").datagrid({
                fit: false,
                loadMsg: '数据加载中，请稍后……',
                method: "get",
                border: true,
                url: '/Business/PaymentRecordQuery',
                queryParams: getParams(),
                pagination: true,
                pageSize: pageSize,
                pageList: [10, 15, 30, 50, 100, 1000],
                height: $(window).height() - 70,
                singleSelect: true,
                rownumbers: true,
                showFooter: true,
                idField: 'orderNo',
                onLoadSuccess: function () {
                    pageSize = $('#pager').datagrid('options').pageSize;
                },
                frozenColumns: frozenColumns,
                columns: columns
            });
        }
    </script>
}


